<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动态参数</title>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
    <style>

    </style>
</head>

<body>
    <div id="app">
        <h1>Hello App!</h1>
        <router-link to="/goods">Go to 商品123</router-link>
        <router-link to="/user">Go to 商品456</router-link>
        <router-view></router-view>
    </div>
</body>
<script>

    const Goods = {
        template: `
        <div>
            <div>商品详情</div>
            <p>{{$route.params.id}}</p>
        </div>    
        ` 
    };
    const User = {
        template:`<div>用户界面</div>`
    }
    const NotFound = {
        template:`<div>页面不存在</div>`
    }

    const routes = [
        {
            path: '/goods',
            component: Goods
        },
        {
            path: '/user',
            component: User
        },
        {
            path: '*',
            component: NotFound
        },
    ]

    // 3. 创建 router 实例，然后传 `routes` 配置
    const router = new VueRouter({
        routes // (缩写) 相当于 routes: routes
    })

    // 4. 创建和挂载根实例。
    // 记得要通过 router 配置参数注入路由，
    // 从而让整个应用都有路由功能
    const app = new Vue({
        router
    }).$mount('#app')

// 现在，应用已经启动了！
</script>

</html>